#include <stddef.h>
#include <stdlib.h>
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
 };
 
//二叉树的前序遍历

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int TreeSize(struct TreeNode* root)
 {
     return root==NULL? 0:TreeSize(root->left)+TreeSize(root->right)+1;
 }
 void Tree_val(struct TreeNode* root,int* tree,int* returnSize)
 {
     if(root==NULL)
     {
        return;
     }
     tree[(*returnSize)++]=root->val;//一个一个赋值
     Tree_val(root->left,tree,returnSize);
     Tree_val(root->right,tree,returnSize);
 } 
int* preorderTraversal(struct TreeNode* root, int* returnSize){
    int i=TreeSize(root);
    int* tree = (int*)malloc(sizeof(int)*i);//Note:开辟数组空间 区间[0,100]
    *returnSize=0;  //从0开始计数
    Tree_val(root,tree,returnSize);
    return tree;
}